<%@page contentType="text/html; charset=utf-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/messages.jsp"%>
<%@ include file="/commons/commonEdit.jsp" %>
<%@ include file="/commons/validation.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<title></title>
<script>
var flag = null;
var sourceValue = null;
var closeFlag = false;
var chrgTypeCode= null;
function ajaxSubmit(){
	var isTrue=$('chargeItemForm').fireEvent("onSubmit");
    if(isTrue){
    	if(flag == "add")
         	var url = "${ctx}/charge_chargeItemAction.do?method=addChargeItem";
        else if(flag == "update")
            var url = "${ctx}/charge_chargeItemAction.do?method=editChargeItem";
        <c:if test="${isReference  == '0'}">
            $('chrgType').value = chrgTypeCode;
        	$('chargeType').value= chrgTypeCode;
        </c:if>
        var param = Form.serialize('chargeItemForm');
        new Ajax.Request(url,{method: 'post',parameters :param ,onSuccess : showResponse});
	}
}
function showResponse(response){
	if('true' == response.responseText){
    	var frameid=findFrame('main');
    	frameid.refreshTree();
    }
    ajaxSubmitException(response.responseText);
	if(!closeFlag){ //点击的保存按钮
        windowClose();
	}
	else {  //点击的保存并新增
        location.reload();
	}
}
function setCloseFlag(flag){
	closeFlag = flag;
}
function showMeterType()
{
	    var chargeType = $('chargeType').options[$('chargeType').selectedIndex].code;
	    chrgTypeCode=chargeType;
		if (chargeType =="002")
			document.getElementById("layer1").style.display="";
		else
			document.getElementById("layer1").style.display="none";
}
</script>
</head>

<body onload="init('${editFlag}')">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle"><span class="window_head_intext" id="item_title"></span></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td class="content"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="aux_outtable_color">
          <form id="chargeItemForm" name="chargeItemForm" method="post" action="" class="required-validate">
          <input type="hidden" id="keyword" name="keyword" value="${chargeItem.keyword}">

          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
          <tr>
            <td class="aux_intable_td1">${key.chargeItemName}：</td>
            <td class="aux_intable_require"><input name="itemName" type="text" class="required validate-char validate-ajax" relativeId="keyword" validateUrl="" size="16" value="${chargeItem.itemName}"></td>
          </tr>
		  <tr>
            <td class="aux_intable_td1">${key.businessCode}：</td>
            <c:if test = "${isReference  == '0'}">
              <td class="aux_intable_require">
              <pms:unitedSelect name="businessCodeId"
            					  id="businessCodeId"
              					  dataList="${businessCodeList}"
              					  optionLabel="bizCode"
              					  optionValue="keyword"
              					  className="select-one-required"
              					  onChange=""
              					  selectText="${key.options}"
              					  value="${chargeItem.businessCodeId}">
               </pms:unitedSelect>
               </c:if>
               <c:if test="${isReference  == '1'}">
               		<td class="aux_intable_td2">${chargeItem.businessDescription}</td>
               		<input type="hidden" name="businessCodeId" value="${chargeItem.businessCodeId}">
               </c:if>
            </td>
          </tr>
          <tr>
            <td class="aux_intable_td1">${key.chargeType}：</td>
              <c:if test = "${isReference  == '0'}">
	              <td class="aux_intable_require">
	              <mypms:Sysrefcode  name="chargeType"
	              					 showTip="true"
	              					 code="FEE_CHAR_TYPE_CLASS_CODE"
	              					 style="width:110px"
	              					 onchange="showMeterType();"
	              					 className="select-one-required"
	              					 >
	              </mypms:Sysrefcode></td>
              </c:if>
              <c:if test="${isReference  == '1'}">
               		<td class="aux_intable_td2">${chargeItem.chrgTypeDisplay}</td>
               </c:if>
              <input type="hidden" name="chrgType" value="${chargeItem.chrgType}">
          </tr>
		  <tbody id="layer1" style="display:none;">
		   <tr>
            <td class="aux_intable_td1">${key.meterType}：</td>
            <c:if test = "${isReference  == '0'}">
            <td class="aux_intable_require">
            	<pms:unitedSelect name="meterType"
            					  id="meterType"
            					  style="width:110px"
              					  dataList="${meterTypeList}"
              					  optionLabel="name"
              					  optionValue="code"
              					  className="select-one-required"
              					  selectText="${key.options}"
              					  value="${chargeItem.meterType}">
               </pms:unitedSelect>
            </td>
            </c:if>
             <c:if test="${isReference  == '1'}">
               		<td class="aux_intable_td2">${chargeItem.meterTypeDisplay}</td>
               		<input type="hidden" name="meterType" value="${chargeItem.meterType}">
               </c:if>
          </tr>
		  </tbody>
		  <tr>
            <td class="aux_intable_td1">${key.seqNo}：</td>
            <td class="aux_intable_require"><input name="seqNo" type="text" class="required validate-ajax int-range-1-32768" relativeId="keyword" validateUrl="" size="16" value="${chargeItem.seqNo}"></td>
          </tr>
		  <tr>
            <td valign="top" class="aux_intable_td1">${key.remark}：</td>
            <td colspan="3" class="aux_intable_td2"><textarea name="remark" cols="30" rows="4" class="textareatext">${chargeItem.remark}</textarea></td>
          </tr>
        </table>
        </form>
        </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td class="window_footer"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" cellpadding="0" cellspacing="0" id="item_submitAgain">
          <tr>
            <td class="buttonOffLeft" id="btn1_41"></td>
            <td class="buttonOffMiddle" id="btn1_42" onClick="setCloseFlag(true);ajaxSubmit('chargeItemForm');" onMouseOver="btn_change_over(4)" onMouseOut="btn_change_out(4)" onblur="btn_change(4)"><img src="${ctx}/images/ico_saveandnewfile.gif" alt="" width="14" height="14" border="0" align="absbottom">${key.saveAndAdd}</td>
            <td class="buttonOffRight" id="btn1_43"></td>
          </tr>
        </table></td>
        <td class="btn_between_space">&nbsp;</td>
        <td><table border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="buttonOffLeft" id="btn1_21"></td>
            <td class="buttonOffMiddle" id="btn1_22" onClick="setCloseFlag(false);ajaxSubmit('chargeItemForm');" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onBlur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom">${key.save}</td>
            <td class="buttonOffRight" id="btn1_23"></td>
          </tr>
          </table></td>
          <td class="btn_between_space"></td>
          <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
                <td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onBlur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom">${key.close}</td>
                <td class="buttonOffRight" id="btn1_33"></td>
              </tr>
          </table></td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
<script>
function init(editFlag){
	if(editFlag == 'add'){//add
		$('item_title').innerText =  "${key.addChargeItem}";
		$('item_submitAgain').style.display="";
		flag = "add";
	}else if(editFlag == 'update'){//update
		$('item_title').innerText = "${key.editChargeItem}";
		$('item_submitAgain').style.display="none";
		flag = "update";
		<c:if test="${isReference  == '0'}">
               	var len = $('chargeType').options.length;
				for(var i = 0 ; i < len ; i++)
				{
					var code = $('chargeType').options[i].code;
					if($('chrgType').value == code)
					{
						$('chargeType').options[i].selected = true;
					}
				}

				showMeterType();
				var mlen = $('meterType').options.length;
				for(var i = 0 ; i < mlen ; i++)
				{
					var v = $('meterType').options[i].value;
					if($('meterType').value == v)
					{
						$('meterType').options[i].selected = true;
					}
				}
        </c:if>
	}
	$('itemName').validateUrl = "${ctx}/charge_chargeItemAction.do?method=checkItemByName";
	$('seqNo').validateUrl = "${ctx}/charge_chargeItemAction.do?method=checkUniqueSeqNO";
	sourceValue=$('chargeItemForm').serialize();
}
</script>
</html>